/*
 * #%L
 * java model
 * %%
 * Copyright (C) 2009 - 2011 prefabware.com Stefan Isele
 * %%
 * All Rights Reserved.
 * This program is dual-licensed under the GNU General Public license
 * or a commercial license.
 * You may select to use one or the other of these licenses.
 * To obtain a commercial license please contact Stefan Isele at www.stefan-isele.de
 * Any modifications to this file must keep this entire header intact.
 * Redistribution, except as permitted by the selected license, is prohibited.
 * #L%
 */
package com.prefabware.jmodel;

import com.prefabware.jmodel.code.JCodeOptions;
import com.prefabware.jmodel.expression.JExpression;
import com.prefabware.jmodel.expression.JVariable;
import com.prefabware.jmodel.javadoc.JFieldJavadoc;

public class JField extends JMember implements JVariable {
	private JExpression initializer;

	public JExpression getInitializer() {
		return initializer;
	}

	public void setInitializer(JExpression initializer) {
		this.initializer = initializer;
	}

	public JField(JFieldDeclaration declaration) {
		super(declaration);
		this.javadoc = new JFieldJavadoc();
	}

	@Override
	public String asCode(JCodeOptions options) {
		//a field may be used in xml with its qualified name !!
		//so the caller or the template has to decide, which option to take
		if (options.isUseQualifiedNames()) {
			return this.getQualifiedName();
		} else {
			return this.getName();
		}
	}

	@Override
	public String toString() {
		return "JField [" + asCode(JCodeOptions.DEFAULT) + "]";
	}

	public JType getType() {
		return getDeclaration().getType();
	}

	@Override
	public JFieldDeclaration getDeclaration() {
		return (JFieldDeclaration) super.getDeclaration();
	}
	
}
